﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DA
{
    public class PhieuThuePhong_DA
    {
        QLKhachSanDataContext ql;
        public List<PhieuThuePhong> LayDSPhieu()
        {
            try
            {
                ql = new QLKhachSanDataContext();
               return ql.PhieuThuePhongs.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
          
        }
        public bool ThemPhieuThuePhong(PhieuThuePhong ph)
        {
            try
            {
                ql = new QLKhachSanDataContext();
                PhieuThuePhong ph1 = new PhieuThuePhong();
                ph1.MaKH = ph.MaKH;
                ph1.MaPhong = ph.MaPhong;
                ph1.SoLuongKhach = ph.SoLuongKhach;
                ph1.NgayDen = ph.NgayDen;
                ph1.NgayDi = ph.NgayDi;
                ql.PhieuThuePhongs.InsertOnSubmit(ph1);
                ql.SubmitChanges();
                return true;
            }
            catch
            {

                return false;
            }
            finally
            {
                ql.Dispose();
            }
        }
        public string layTenKHtheomaphong(string map)
        {
            try
            {
                ql = new QLKhachSanDataContext();
                return ql.PhieuThuePhongs.Where(p => p.MaPhong == map).Select(p => p.KhachHang.TenKH).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ql.Dispose();
            }
        }
        public string layLoaiKHtheomaphong(string map)
        {
            try
            {
                ql = new QLKhachSanDataContext();
                return ql.PhieuThuePhongs.Where(p => p.MaPhong == map).Select(p => p.KhachHang.LoaiKhach).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ql.Dispose();
            }
        }
        public string laymaKHtheomaphong(string map)
        {
            try
            {
                ql = new QLKhachSanDataContext();
                return ql.PhieuThuePhongs.Where(p => p.MaPhong == map).Select(p => p.KhachHang.MaKH).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ql.Dispose();
            }
        }

    }
}
